home *** CD-ROM | disk | FTP | other *** search
-
- #include <Files.h>
- #include <StandardFile.h>
-
-
-
- PicHandle InitPicture(void);
- void PutPictToFile(PicHandle thePicture);
-
- /*------ main ----------------------------------------------------------------------------*/
-
- PicHandle ourPict;
-
- main()
-
- {
-
- GrafPort myPort;
-
-
- InitGraf((Ptr) &thePort);
- OpenPort(&myPort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- ourPict = InitPicture(); // get our picture
- PutPictToFile(ourPict); // put it to a file
- KillPicture(ourPict); // and then kill it
-
- } /* main */
-
-
-
- /*------ PutPictToFile ----------------------------------------------------------------------------*/
-
-
- void PutPictToFile(PicHandle thePicture)
-
- {
-
- SFReply tr;
- short rc, fRefNum, count;
- long inOutCount;
- Point where;
- unsigned char header[512];
- OSErr myError;
-
- for (count = 0; count < 512; count++)
- header[count] = 0x00;
-
- where.h=100; where.v=50; /* where the Standard File dialog window goes */
-
- SFPutFile( where, "\pSave PICT as:", "\pMy PICT File", NULL, &tr );
-
- if ( tr.good ) {
- myError = Create(tr.fName, tr.vRefNum, '????', 'PICT');
- if (myError == dupFNErr) {
- myError = FSDelete(tr.fName,tr.vRefNum);
- myError = Create(tr.fName, tr.vRefNum, '????', 'PICT');
- } /* this is quick 'n' dirty or there'd be more robust handling here */
-
- myError = FSOpen( tr.fName, tr.vRefNum, &fRefNum );
- if ( myError == noErr ) {
- inOutCount = 512;
- myError = FSWrite(fRefNum, &inOutCount, header); /* write the header */
- HLock((Handle)thePicture);
- if (myError == noErr) { /* don't write if error the first time */
- inOutCount = GetHandleSize((Handle)thePicture);
- myError == FSWrite(fRefNum,&inOutCount,*thePicture);
- }
- FSClose( fRefNum ); /* close it */
- HUnlock((Handle)thePicture);
- }
- }
- }
-
-
-
- /*------ InitPicture ----------------------------------------------------------------------*/
-
- PicHandle InitPicture (void)
-
- {
- Rect myRect;
- PicHandle thePicHandle;
- Ptr theOldPictPtr, theNewPictPtr;
- CGrafPort myPort;
- long scrapResult;
- unsigned long thePictureSize;
- PixPatHandle thePixPat;
- short theFont, textSize = 14;
-
- OpenCPort(&myPort);
- SetRect(&myRect,0,0,200,200);
- thePicHandle = OpenPicture(&myRect);
- ClipRect(&myRect);
-
- thePixPat = GetPixPat(128);
-
- FillCOval(&myRect,thePixPat);
-
- MoveTo(22,22);
- LineTo(55,55);
- LineTo(58,22);
- LineTo(22,58);
-
- GetFNum ("\pTimes", &theFont);
- TextFont (theFont);
- TextSize (textSize);
-
- DrawString("\pA wonderful test");
-
- ClosePicture();
- CloseCPort(&myPort);
-
- return(thePicHandle);
-
- } /* InitPicture */
-